package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.api.domain.BmWarehouse;
import com.ruoyi.system.service.IBmWarehouseService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * #仓库信息Controller
 * 
 * @author ruoyi
 * @date 2023-08-02
 */
@RestController
@RequestMapping("/warehouse")
public class BmWarehouseController extends BaseController
{
    @Autowired
    private IBmWarehouseService bmWarehouseService;

    /**
     * 查询#仓库信息列表
     */
    @RequiresPermissions("system:warehouse:list")
    @GetMapping("/list")
    public TableDataInfo list(BmWarehouse bmWarehouse)
    {
        startPage();
        List<BmWarehouse> list = bmWarehouseService.selectBmWarehouseList(bmWarehouse);
        return getDataTable(list);
    }

    @RequiresPermissions("system:warehouse:list")
    @GetMapping("/getListWarehouse")
    public AjaxResult getWarehouseList(BmWarehouse bmWarehouse)
    {
        List<BmWarehouse> list = bmWarehouseService.selectBmWarehouseList(bmWarehouse);
        return AjaxResult.success(list);
    }

    @RequiresPermissions("system:warehouse:list")
    @GetMapping("/getWarehouseList")
    public List<BmWarehouse> getWarehouseList()
    {
        List<BmWarehouse> list = bmWarehouseService.selectBmWarehouseList(null);
        return list;
    }


    /**
     * 导出#仓库信息列表
     */
    @RequiresPermissions("system:warehouse:export")
    @Log(title = "#仓库信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BmWarehouse bmWarehouse)
    {
        List<BmWarehouse> list = bmWarehouseService.selectBmWarehouseList(bmWarehouse);
        ExcelUtil<BmWarehouse> util = new ExcelUtil<BmWarehouse>(BmWarehouse.class);
        util.exportExcel(response, list, "#仓库信息数据");
    }

    /**
     * 获取#仓库信息详细信息
     */
    @RequiresPermissions("system:warehouse:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bmWarehouseService.selectBmWarehouseById(id));
    }

    /**
     * 获取#仓库信息详细信息
     */
    @RequiresPermissions("system:warehouse:query")
    @GetMapping(value = "/getInfoByCode/{warehouseCode}")
    public AjaxResult getInfo(@PathVariable("warehouseCode") String warehouseCode){
        return AjaxResult.success(bmWarehouseService.selectBmWarehouseByCode(warehouseCode));
    }

    /**
     * 新增#仓库信息
     */
    @RequiresPermissions("system:warehouse:add")
    @Log(title = "#仓库信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BmWarehouse bmWarehouse)
    {
        return toAjax(bmWarehouseService.insertBmWarehouse(bmWarehouse));
    }

    /**
     * 修改#仓库信息
     */
    @RequiresPermissions("system:warehouse:edit")
    @Log(title = "#仓库信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BmWarehouse bmWarehouse)
    {
        return toAjax(bmWarehouseService.updateBmWarehouse(bmWarehouse));
    }

    /**
     * 删除#仓库信息
     */
    @RequiresPermissions("system:warehouse:remove")
    @Log(title = "#仓库信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bmWarehouseService.deleteBmWarehouseByIds(ids));
    }

    @GetMapping("/merge/{ids}")
    public AjaxResult mergeWarehouse(@PathVariable Long[] ids){
        Boolean result = bmWarehouseService.mergeWarehouse(ids);
        return result?AjaxResult.success("合并成功"):AjaxResult.error("不符合合并条件");
    }

    @GetMapping("/selectMaxId")
    public Long selectMaxId(){
        return bmWarehouseService.selectMaxId();
    }
}
